package io.renren.modules.cus.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.datasources.DataSourceNames;
import io.renren.datasources.DynamicDataSource;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.cus.entity.TPmUserEntity;
import io.renren.modules.cus.service.TPmUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * ${comments}
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-01-30 09:17:10
 */
@RestController
@RequestMapping("cus/tpmuser")
public class TPmUserController {
    @Autowired
    private TPmUserService TPmUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("cus:tpmuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = TPmUserService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{fid}")
    @RequiresPermissions("cus:tpmuser:info")
    public R info(@PathVariable("fid") String fid){
        DynamicDataSource.setDataSource(DataSourceNames.SECOND);
		TPmUserEntity TPmUser = TPmUserService.selectById(fid);
        return R.ok().put("TPmUser", TPmUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("cus:tpmuser:save")
    public R save(@RequestBody TPmUserEntity TPmUser){
			TPmUserService.insert(TPmUser);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("cus:tpmuser:update")
    public R update(@RequestBody TPmUserEntity TPmUser){
			TPmUserService.updateById(TPmUser);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("cus:tpmuser:delete")
    public R delete(@RequestBody String[] fids){
			TPmUserService.deleteBatchIds(Arrays.asList(fids));

        return R.ok();
    }

}
